home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / appletalk / netatalk / afs / afsprivsrc.sit.hqx / AFS Privileges 1.50 / helptextedit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-21  |  7.9 KB  |  332 lines

  1. #include    <Types.h>
  2. #include    <Files.h>
  3. #include    <Devices.h>
  4. #include    <Quickdraw.h>
  5. #include    <OSUtils.h>
  6. #include    <CType.h>
  7. #include    <Dialogs.h>
  8. #include    <Desk.h>
  9. #include     <Icons.h>
  10. #include    <Errors.h>
  11. #include    <Resources.h>
  12. #include     <Lists.h>
  13. #include    <Memory.h>
  14. #include    <SysEqu.h>
  15. #include    <OSEvents.h>
  16. #include    <Packages.h>
  17. #include    <ToolUtils.h>
  18. #include    <StdIO.h>
  19. #include    <String.h>
  20. #include    <Fonts.h>
  21. #include    <GestaltEqu.h>
  22. #include    <Menus.h>
  23. #include     <Sound.h>
  24. #include    <Traps.h>
  25. #include     <Windows.h>
  26. #include    <Quickdraw.h>
  27.  
  28. #define     Rez
  29. #include    "privileges.h"
  30.  
  31. ControlHandle    vScrollH;
  32. TEHandle    infoTEH;
  33.  
  34. pascal Boolean infoFilter(DialogPtr ,EventRecord *,short *);
  35.  
  36. short
  37. calcNumVisibleLines(TEHandle theTEH,short startLine)
  38. {
  39.     Rect            box;
  40.     short            lineHeight,nLines,numLines=0;
  41.  
  42. box=(**theTEH).destRect;
  43. lineHeight=(**theTEH).lineHeight;
  44. nLines=(**theTEH).nLines;
  45. while( true )    {
  46.     if (startLine > nLines)    break;
  47.     if (lineHeight==-1)    {
  48.         box.top+=TEGetHeight((long)startLine,(long)startLine,theTEH);
  49.         }
  50.     else    {
  51.         box.top+=lineHeight;
  52.         }
  53.     if (box.top > box.bottom)    break;
  54.     ++startLine;
  55.     ++numLines;
  56.     }
  57. return(numLines);
  58. }
  59.  
  60. void blinkButton(DialogPtr theDialog, short itemNum){
  61.  
  62.     Handle        itemH;
  63.     Rect        box;
  64.     short        itemType;
  65.  
  66.     GetDItem(theDialog,itemNum,&itemType,&itemH,&box);
  67.     
  68.     HiliteControl((ControlHandle)itemH,10 );
  69.     HiliteControl((ControlHandle)itemH, 1 );
  70. }
  71.  
  72.  
  73. void
  74. frameButton(DialogPtr theDialog,short itemNum,short textItem1,short textItem2)
  75. {
  76.     Handle        itemH;
  77.     Rect        box;
  78.     Str255        theText;
  79.     short        itemType,OKhiliteState=255;
  80.     long        pattern[2];
  81.  
  82. SetPort((GrafPtr)theDialog);
  83. if (textItem1)    {
  84.     pattern[0]=pattern[1]=0xAA55AA55;
  85.     GetDItem(theDialog,textItem1,&itemType,&itemH,&box);
  86.     GetIText(itemH,(void *)&theText);
  87.     if (theText[0])    {
  88.         GetDItem(theDialog,textItem2,&itemType,&itemH,&box);
  89.         GetIText(itemH,(void *)&theText);
  90.         if (theText[0])    {
  91.             OKhiliteState=0;
  92.             pattern[0]=pattern[1]=0xFFFFFFFF;
  93.             }
  94.         }
  95.     GetDItem(theDialog,itemNum,&itemType,&itemH,&box);
  96.     if ((**((ControlHandle)itemH)).contrlHilite != OKhiliteState)    {
  97.         HiliteControl((ControlHandle)itemH,OKhiliteState);
  98.         }
  99.     PenPat((void *)&pattern);
  100.     }
  101. GetDItem(theDialog,ITEM_OK,&itemType,&itemH,&box);
  102. InsetRect(&box,-4,-4);
  103. PenSize(3,3);
  104. FrameRoundRect(&box,16,16);
  105. PenNormal();
  106. }
  107.  
  108. void
  109. showInfoDialog()
  110. {
  111.     DialogPtr        theDialog;
  112.     Handle            itemH,textH;
  113.     Rect            box;
  114.     StScrpHandle    styleH=NULL;
  115.     short            itemHit,itemType,numLines;
  116.     long            response;
  117.  
  118. if (theDialog=GetNewDialog( DITL_INFO,0L,(WindowPtr)(-1L)))    {
  119.     SetPort((GrafPtr)theDialog);
  120.     
  121.     GetDItem(theDialog,INFO_ITEM,&itemType,&itemH,&box);
  122.     box.right-=15;
  123.     InsetRect(&box,4,4);
  124.  
  125.     if (Gestalt(gestaltTextEditVersion,&response))    response=0L;
  126.     if (response >= gestaltTE1)    {
  127.         infoTEH=TEStylNew(&box,&box);
  128.         if (styleH=(StScrpHandle)Get1Resource('styl',TEXT_INFO))    {
  129.             HNoPurge((Handle)styleH);
  130.             MoveHHi((Handle)styleH);
  131.             HLock((Handle)styleH);
  132.             }
  133.         }
  134.     else    {
  135.         infoTEH=TENew(&box,&box);
  136.         }
  137.  
  138.     if (infoTEH)    {
  139.         if (textH=Get1Resource('TEXT',TEXT_INFO))    {
  140.             HNoPurge(textH);
  141.             MoveHHi(textH);
  142.             HLock(textH);
  143.             
  144.             if (response >= gestaltTE1 && styleH)    {
  145.                 TEStylInsert(*textH,GetHandleSize(textH),styleH,infoTEH);
  146.                 }
  147.             else    {
  148.                 TESetText(*textH,GetHandleSize(textH),infoTEH);
  149.                 }
  150.             TECalText(infoTEH);
  151.             GetDItem(theDialog,INFO_ITEM,&itemType,&itemH,&box);
  152.             box.left=box.right-16;
  153.             numLines=(**infoTEH).nLines-calcNumVisibleLines(infoTEH,1);
  154.             vScrollH=NewControl((WindowPtr)theDialog,&box,"\p",true,1,1,numLines,scrollBarProc,0L);
  155.  
  156. //            centerDialog(theDialog);
  157.             FlushEvents(mDownMask+mUpMask+keyDownMask+keyUpMask,0);
  158.             ShowWindow((WindowPtr)theDialog);
  159.             while ( true )    {
  160.                 ModalDialog((void *)infoFilter,&itemHit);
  161.                 if (itemHit==ITEM_OK)    break;
  162.                 }
  163.             }
  164.         TEDispose(infoTEH);
  165.         }
  166.     if (vScrollH)    DisposeControl(vScrollH);
  167.     DisposDialog(theDialog);
  168.     }
  169. }
  170.  
  171. pascal void
  172. scrollBarActionProc(ControlHandle theControl,short partCode)
  173. {
  174.     Rect        box;
  175.     short        currentVal,lineHeight,numLines;
  176.  
  177. currentVal=GetCtlValue(theControl);
  178. switch(partCode)    {
  179.     case    inUpButton:
  180.     if (currentVal-- > GetCtlMin(theControl))    {
  181.         if ((lineHeight=(**infoTEH).lineHeight)==-1)    {
  182.             lineHeight=TEGetHeight((long)currentVal,(long)currentVal,infoTEH);
  183.             }
  184.         SetCtlValue(theControl,currentVal);
  185.         TEScroll(0,lineHeight,infoTEH);
  186.         }
  187.     break;
  188.  
  189.     case    inDownButton:
  190.     if (currentVal < GetCtlMax(theControl))    {
  191.         if ((lineHeight=(**infoTEH).lineHeight)==-1)    {
  192.             lineHeight=TEGetHeight((long)currentVal,(long)currentVal,infoTEH);
  193.             }
  194.         SetCtlValue(theControl,++currentVal);
  195.         TEScroll(0,-lineHeight,infoTEH);
  196.         }
  197.     break;
  198.  
  199.     case    inPageUp:
  200.     numLines=0;
  201.     box=(**infoTEH).destRect;
  202.     while ( true )    {
  203.         if (--currentVal < GetCtlMin(theControl))    break;
  204.         if ((lineHeight=(**infoTEH).lineHeight)==-1)    {
  205.             lineHeight=TEGetHeight((long)currentVal,(long)currentVal,infoTEH);
  206.             }
  207.         box.top+=lineHeight;
  208.         if (box.top >= box.bottom)    break;
  209.         ++numLines;
  210.         }
  211.     if (numLines>0)    {
  212.         currentVal=GetCtlValue(theControl);
  213.         lineHeight=TEGetHeight((long)currentVal-1,(long)currentVal-numLines,infoTEH);
  214.         SetCtlValue(theControl,currentVal-numLines);
  215.         TEScroll(0,lineHeight,infoTEH);
  216.         }
  217.     break;
  218.  
  219.     case    inPageDown:
  220.     numLines=0;
  221.     box=(**infoTEH).destRect;
  222.     while ( true )    {
  223.         if (currentVal >= GetCtlMax(theControl))    break;
  224.         if ((lineHeight=(**infoTEH).lineHeight)==-1)    {
  225.             lineHeight=TEGetHeight((long)currentVal,(long)currentVal,infoTEH);
  226.             }
  227.         box.top+=lineHeight;
  228.         if (box.top >= box.bottom)    break;
  229.         ++currentVal;
  230.         ++numLines;
  231.         }
  232.     if (numLines>0)    {
  233.         currentVal=GetCtlValue(theControl);
  234.         lineHeight=TEGetHeight((long)currentVal+numLines-1,(long)currentVal,infoTEH);
  235.         SetCtlValue(theControl,currentVal+numLines);
  236.         TEScroll(0,-lineHeight,infoTEH);
  237.         }
  238.     break;
  239.     }
  240. }
  241.  
  242. void
  243. scrollDelta(ControlHandle theControl,short startVal,short delta)
  244. {
  245.     short        lineHeight;
  246.  
  247. if (delta && theControl)    {
  248.     if (delta>0)    {
  249.         lineHeight=-TEGetHeight((long)startVal+delta-1,(long)startVal,infoTEH);
  250.         }
  251.     else    {
  252.         lineHeight=TEGetHeight((long)startVal-1,(long)startVal+delta,infoTEH);
  253.         }
  254.     TEScroll(0,lineHeight,infoTEH);
  255.     }
  256. }
  257.  
  258.  
  259. pascal Boolean
  260. infoFilter(DialogPtr theDialog,EventRecord *theEvent,short *itemHit)
  261. {
  262.     Boolean                retVal=false;
  263.     Handle                itemH;
  264.     Point                where;
  265.     Rect                box;
  266.     short                delta,itemType,newVal,partCode,val;
  267.     unsigned short            key,vKey;
  268.     
  269. SetPort((GrafPtr)theDialog);
  270. switch(theEvent->what)    {
  271.     case    autoKey:
  272.     case    keyDown:
  273.     key=(unsigned short)(theEvent->message & charCodeMask);
  274.     vKey=(unsigned short)((theEvent->message & keyCodeMask) >> 8);
  275.  
  276.     if (vKey==ENTER_KEY || vKey==RETURN_KEY)    {
  277.         blinkButton(theDialog,ITEM_OK);
  278.         *itemHit=ITEM_OK;
  279.         retVal=true;
  280.         }
  281.     else if (vKey==UP_ARROW || vKey==OLD_UP_ARROW)        scrollBarActionProc(vScrollH,inUpButton);
  282.     else if (vKey==DOWN_ARROW || vKey==OLD_DOWN_ARROW)    scrollBarActionProc(vScrollH,inDownButton);
  283.     else if (vKey==PAGE_UP)                    scrollBarActionProc(vScrollH,inPageUp);
  284.     else if (vKey==PAGE_DOWN)                scrollBarActionProc(vScrollH,inPageDown);
  285.     else if (vKey==HOME_KEY || vKey==END_KEY)    {
  286.         val=GetCtlValue(vScrollH);
  287.         newVal=(vKey==HOME_KEY)    ? GetCtlMin(vScrollH) : GetCtlMax(vScrollH);
  288.         delta=newVal-val;
  289.         SetCtlValue(vScrollH,newVal);
  290.         scrollDelta(vScrollH,val,delta);
  291.         }
  292.     break;
  293.  
  294.     case    mouseDown:
  295.     if (infoTEH)    {
  296.         where=theEvent->where;
  297.         GlobalToLocal(&where);
  298.         if (partCode=TestControl(vScrollH,where))    {
  299.             if (partCode==inThumb)    {
  300.                 val=GetCtlValue(vScrollH);
  301.                 TrackControl(vScrollH,where,NULL);
  302.                 newVal=GetCtlValue(vScrollH);
  303.                 if (newVal != val)    {
  304.                     scrollDelta(vScrollH,val,newVal-val);
  305.                     }
  306.                 }
  307.             else    {
  308.                 TrackControl(vScrollH,where,(ProcPtr)scrollBarActionProc);
  309.                 }
  310.             }
  311.         }
  312.     break;
  313.  
  314.     case    updateEvt:
  315.     if (theDialog==((DialogPtr)(theEvent->message)))    {
  316.         SetPort((GrafPtr)theDialog);
  317.         PenNormal();
  318.         GetDItem(theDialog, INFO_ITEM,&itemType,&itemH,&box);
  319.         box.right-=15;
  320.         FrameRect(&box);
  321.         InsetRect(&box,1,1);
  322.         EraseRect(&box);
  323.         InsetRect(&box,3,3);
  324.         if (infoTEH)    TEUpdate(&box,infoTEH);
  325.         if (vScrollH)    Draw1Control(vScrollH);
  326.         frameButton( theDialog,ITEM_OK, false, false );
  327.         }
  328.     break;
  329.     }
  330. return(retVal);
  331. }
  332.